/**
 * 工具函数封装
 */
export default {
    formateDate(date, rule) {
        let fmt = rule || 'yyyy-MM-dd hh:mm:ss'
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, date.getFullYear())
        }
        const o = {
            // 'y+': date.getFullYear(),
            'M+': date.getMonth() + 1,
            'd+': date.getDate(),
            'h+': date.getHours(),
            'm+': date.getMinutes(),
            's+': date.getSeconds()
        }
        for (let k in o) {
            if (new RegExp(`(${k})`).test(fmt)) {
                const val = o[k] + '';
                fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? val : ('00' + val).substr(val.length));
            }
        }
        return fmt;
    },
    
    setStorage(key, value) {
        if(typeof value==='object') {

           value=JSON.stringify(value)
            
           }
            
        window.localStorage.setItem(key, value)
       
    },
    
    getStorage(key) {
        const data = window.localStorage.getItem(key)

        try{
        
            return JSON.parse(data)
        
        }catch(err){
        
            return data
        
        } 
       
    },
    
    delStorage(key) {

        window.localStorage.removeItem(key)
    },
}